﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CCWin;
using Top.Api;
using Top.Api.Request;
using Top.Api.Response;

namespace InterfaceView
{
    public partial class Register : CCSkinMain
    {
        public Register()
        {
            InitializeComponent();

        }
        static Random rd = new Random();
        static string rnum = Convert.ToString(rd.Next(1000, 10000));
        public bool validateInput()
        {
            if (this.skinTextBox1_user.Text.Length == 0 || this.skinTextBox2_pwd.Text.Length == 0)
            {
                MessageBox.Show("UserName or Password can not Empty ! ");
                this.skinTextBox1_user.Focus();
                return false;
            }
            return true;
        }

        private void skinButton1_ok_Click(object sender, EventArgs e)
        {
            if (this.skinTextBox2_code.Text != rnum)
            {
                MessageBox.Show("Identifying Code Error!");
            }
            else
            {
                if (validateInput())
                {
                    string username = this.skinTextBox1_user.Text;
                    string userpwd = this.skinTextBox2_pwd.Text;
                    string userphone = this.skinTextBox1_phone.Text;
                    if (BusinessLogic.Login.Registered(username, userpwd,userphone) != 0)
                    {
                        MessageBox.Show("ManagerUser have Registered!");
                        this.Hide();
                        Select select = new Select();
                        select.Show();
                    }
                }
            }
        }
       
        private void skinButton2_cancle_Click(object sender, EventArgs e)
        {
            this.Close();
            Select select = new Select();
            select.Show();
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Identifying Code have sent , Please wait for moment!");
            string secret = "66ab455b94bd30f9df7cd1636c2a81d1";
            string url = @"http://gw.api.taobao.com/router/rest";
            string appkey = "23285482";
            ITopClient client = new DefaultTopClient(url, appkey, secret);
            AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
            req.Extend = "123456";
            req.SmsType = "normal";
            req.SmsFreeSignName = "章氏国际酒店";
            req.SmsParam = "{\"code\":\""+rnum+"\",\"product\":\"Zhang International Hotel of Manager\"}";
            string phoneNum = this.skinTextBox1_phone.Text; 
            req.RecNum = phoneNum;
            req.SmsTemplateCode = "SMS_3450194";
            AlibabaAliqinFcSmsNumSendResponse rsp = client.Execute(req);
            Console.WriteLine(rsp.Body);
        }
    }
}
